package com.lkd.handler;

import com.lkd.business.MsgHandler;
import com.lkd.config.TopicConfig;
import com.lkd.contract.SupplyChannel;
import com.lkd.contract.SupplyContract;
import com.lkd.emq.Topic;
import com.lkd.exception.LogicException;
import com.lkd.feign.VMService;
import com.lkd.job.XxlJobConfig;
import com.lkd.service.VendingMachineService;
import com.lkd.utils.JsonUtil;
import com.xxl.job.core.log.XxlJobLogger;
import com.xxl.job.core.util.ShardingUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.List;

@Component
@Topic(TopicConfig.VMS_SUPPLY_TOPIC)
@Slf4j
public class TaskSupply implements MsgHandler {
    @Autowired
    VendingMachineService machineService;
    @Override
    public void process(String jsonMsg) throws IOException {
        //解析协议类
        SupplyContract supplyContract = JsonUtil.getByJson(jsonMsg, SupplyContract.class);
        if (supplyContract == null) {
            throw new LogicException("接收方未获得补货工单的信息");
        }
        List<SupplyChannel> supplyChannelList = supplyContract.getSupplyData();
        String innerCode = supplyContract.getInnerCode();
        //调用补货业务逻辑
        machineService.supply(innerCode,supplyChannelList);


    }
}
